home *** CD-ROM | disk | FTP | other *** search
- Path: populus.slu.se!newsmgr
- From: Thomas.Johansson@stax.slu.se (Thomas Johansson)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q]Assigning function pointer in C/C++.
- Date: 22 Jan 1996 15:18:06 GMT
- Organization: SLU UmeĎ
- Message-ID: <4e09re$kit@populus.slu.se>
- References: <DL3JJu.5nB.0.queen@torfree.net> <4doc42$gsb@bmdhh222.bnr.ca> <ALUN.CHAMPION.96Jan19113523@g7240065.bridge.bst.bls.com>
- NNTP-Posting-Host: b93.resgeom.slu.se
- X-Newsreader: WinVN 0.92.1
-
- In article <ALUN.CHAMPION.96Jan19113523@g7240065.bridge.bst.bls.com>, Alun.Champion@bridge.bst.bls.com (Alun Champion) says:
- >
- > -- snip
- >
- >Huh?
- >
- >You can have pointers to member functions providing you know what class (or base
- >class) you are going to be assigning functions from.
- >
- > int (A::*p)(void);
- >
- >declares p as a pointer to an A member function which takes nothing and returns
- >an int. The usage of p requires an object or pointer to an object of
- >type A or derived from A. i.e:
- >
- > A a;
- > int z = (a.*p)(); // Uses '.*' operator.
- >or
- -- snip
-
- Is there any way that you can declare a variable to hold the resulting pointer,
- or must it be 'used' right away ?
-
- something like
-
- typdef int (A::*p)(void) Fp; // Fp is a type of 'pointer to member function'
-
- Fp f = (a.*p); // the object a (of class A) has a member p
-
- int z = f();
-
- I cannot make this work with Borland 4.5.
-
- Regards
- Thomas
-